<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const EventCenter = (function(){
        let events = {}
        let listener, remove, trigger;

        listener = (name,fn) =>{
          events[name] = events[name] || []
          events[name].push(fn)
        }

        remove = (name) =>{
          delete events[name]
        }

        trigger = (name,...args) =>{
          if(!name || !events[name]) return;
          let fns = events[name] || [];
          for(let i = 0, len = fns.length; i < len; i++){
            fns[i].call(null,args)
          }
        }

        return {
          listener, remove, trigger
        }
      })()

      EventCenter.listener("color",(args)=>{
        console.log(args)
      })

      EventCenter.trigger("color", 111)
      
      EventCenter.trigger("color1")

      EventCenter.remove("color")

      EventCenter.trigger("color", 222)

    </script>
  </body>
</html>
